package com.by.controller;

import com.by.bean.Dict;
import com.by.common.bean.ResultBean;
import com.by.common.controlller.BaseController;
import com.by.common.group.V;
import com.by.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "字典管理")
@RequestMapping("/api")

public class DictController<T> extends BaseController {
    @Autowired
     DictService dictService;

//    public  ResultBean get(String id){
//        Object rs = dictService.get(id);
//        return <T> get(rs);
//    }


    @PostMapping("/dict")
    @ApiOperation("保存字典")
    public ResultBean save(@Validated Dict dict, BindingResult result) {
        V.validate(result);
       int rs= dictService.save(dict);
       return saveResult(rs) ;
    }


    @ApiOperation("根据pid查询字典")
    @GetMapping({"/dict/child"})
    public ResultBean<List<Dict>> query(@RequestParam(required = true) int pid) {
        List list = dictService.query(pid);
        return success("字典列表",list);
    }



//    @PutMapping("/dict")
//    @ApiOperation("删除字典")
//    public  ResultBean delete(@RequestParam int id) {
//        int rs= dictService.delete(id);
//        return deleteResult(rs) ;
//    }
//
//
//    @ApiOperation("修改字典")
//    @PutMapping("/dict")
//    public ResultBean update(@RequestBody Dict dict) {
//        int rs= dictService.update(dict);
//        return updateResult(rs) ;
//
//    }








}
